package com.rbac.api.config;


import com.rbac.api.interceptor.CheckLoginInterceptor;
import com.rbac.api.interceptor.CheckPowerInterceptor;
import com.rbac.utils.config.DepCommonRequestConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;



@Configuration
public class ApiRequestConfig extends DepCommonRequestConfig {



    //校验登录拦截器
    @Bean
    public CheckLoginInterceptor checkLoginInterceptor(){
        return  new CheckLoginInterceptor();
    }

    //校验权限拦截器
    @Bean
    public CheckPowerInterceptor checkPowerInterceptor(){
        return  new CheckPowerInterceptor();
    }



    //拦截器按照顺序执行
    @Override
    public void addInterceptors(final InterceptorRegistry registry){

        //检测登录
        registry.addInterceptor(checkLoginInterceptor())
                //公共方法
                .addPathPatterns("/admin/check/**")
                .addPathPatterns("/admin/common/**");

        //检测权限
        registry.addInterceptor(checkPowerInterceptor())
                //公共方法
                .addPathPatterns("/admin/check/**");

        //注册到父类
        super.addInterceptors(registry);
    }


}
